#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool compare(vector<int>& a, vector<int>& b)
{
    return a[1] < b[1];
}

int maxActivities(vector<vector<int> >& a)
{
    if (a.empty())
        return 0;

    sort(a.begin(), a.end(), compare);

    int k = 1;
    int prevEnd = a[0][1];

    for (int i = 1; i < a.size(); i++)
        if (a[i][0] >= prevEnd)
        {
            k++;
            prevEnd = a[i][1];
        }

    return k;
}

int main()
{
    int n;
    cin >> n;

    vector<vector<int>> a(n, vector<int>(2));
    for (int i = 0; i < n; i++)
        cin >> a[i][0] >> a[i][1];

    int ans = maxActivities(a);
    cout << ans << endl;

    return 0;
}